/**
*      author: Y_Yao
*      created: 2025-04-07 12:44:26
**/

#include<bits/stdc++.h>

#define int LL
using namespace std;
using LL = long long;
const LL LLINF = 9e18;
const int INF = 0x3f3f3f3f;
const int N = 4e3 + 7;
int n;
string s;
int r,g,b;

void solve()
{
    cin >> n;
    cin >> s;
    for(auto& e : s)
    {
        if(e == 'R') r++;
        else if(e == 'G') g++;
        else b++;
    }
    int ans = r * b * g;
    for(int i = 0;i < n;i++)
    {
        for(int len = 1;len < n;len++)
        {
            if(i + len + len < n)
            {
                if(s[i] != s[i + len] && s[i] != s[i + len + len] && s[i + len] != s[i + len + len])
                {
                    ans--;
                }
            }
        }
    }
    cout << ans << endl;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    // cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}